import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { 
    path: '/index', 
    component:() => import('../view/index'),
    redirect: '/index/banners',
    meta: { title: '首页' },
    children: [
      { 
        path: 'banners',
        meta: { title: '轮播图管理' }, 
        component:() => import('../view/shouye/banner'),
        beforeEnter: (to, from,next) => {
          console.log('独享守卫')
          next()
        }
      },
      { path: 'category',meta: { title: '分类管理' }, component:() => import('../view/shouye/category') },
      { path: 'recomend',meta: { title: '为您推荐管理' }, component:() => import('../view/shouye/recomend') },
      { path: 'news',meta: { title: '新闻管理' }, component:() => import('../view/news/news') },
      { path: 'brand',meta: { title: '品牌管理' }, component:() => import('../view/goods/brand') },
      { path: 'fenlei',meta: { title: '分类管理' }, component:() => import('../view/goods/fenlei') },
      { path: 'goods',meta: { title: '商品管理' }, component:() => import('../view/goods/goods') },
      { path: 'one',meta: { title: '单品管理' }, component:() => import('../view/goods/one') }
    ]
  },
  { path: '/login', component:() => import('../view/login') }
]

const router = new VueRouter({
  routes // `routes: routes` 的缩写
})

router.beforeEach((to, from,next) => {
  // ...
  // 返回 false 以取消导航
  //console.log(to,from)
  next()
  //return true
})

export default router